<?php
/**
 * LilBlogs plugin
 * This is a plugin which handles common posts scenario
 *
 * @copyright     Copyright (c) 2010, Miha Nahtigal
 * @link          http://www.nahtigal.com/
 * @package       lil_blogs_plugin
 * @subpackage    lil_blogs_plugin.controllers
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */
App::import('Controller', 'Lil.LilPlugin');
/**
 * LilBlogsPluginController class
 *
 * @uses          LilBlogsPluginController
 * @package       lil_blogs_plugin
 * @subpackage    lil_blogs_plugin.controllers
 */
class LilBlogsPluginController extends LilPluginController {
	var $name = 'LilBlogsPlugin';
/**
 * handlers property
 *
 * @var array
 * @access public
 */
	var $handlers = array(
		'admin_sidebar' => array('function' => '_setAdminSidebar', 'params' => array())
	);
/**
 * _setAdminSidebar method
 *
 * Add admin sidebar elements.
 *
 * @param mixed $model
 * @access public
 * @return void
 */
	function _setAdminSidebar($controller, $sidebar) {
		$blogs['visible'] = $this->getAdminAreaId();
		$blogs['items'] = array(
			'posts' => array(
				'visible' => true,
				'title' => __d('lil_blogs', 'Posts', true),
				'url'   => array(
					'plugin'     => 'lil_blogs',
					'controller' => 'posts',
					'action'     => 'index',
					'admin'      => true,
				),
				'params' => array(),
				'active' => in_array($this->params['controller'], array('posts', 'categories')),
				'expand' => in_array($this->params['controller'], array('posts', 'categories')),
				'submenu' => array(
					'edit' => array(
						'visible' => true,
						'title' => __d('lil_blogs', 'Edit', true),
						'url'   => array(
							'plugin'     => 'lil_blogs',
							'controller' => 'posts',
							'action'     => 'index',
							'admin'      => true,
						),
						'params' => array(),
						'active' =>
							$this->params['controller'] == 'posts' &&
							in_array($this->params['action'], array('edit', 'index'))
					),
					'add' => array(
						'visible' => true,
						'title' => __d('lil_blogs', 'Add New', true),
						'url'   => array(
							'plugin'     => 'lil_blogs',
							'controller' => 'posts',
							'action'     => 'add',
							'admin'      => true,
						),
						'params' => array(),
						'active' =>
							($this->params['controller'] == 'posts') &&
							($this->params['action'] == 'add')
					),
					'categories' => array(
						'visible' => true,
						'title' => __d('lil_blogs', 'Categories', true),
						'url'   => array(
							'plugin'     => 'lil_blogs',
							'controller' => 'categories',
							'action'     => 'index',
							'admin'      => true,
						),
						'params' => array(),
						'active' => $this->params['controller']=='categories'
					),
				)
			)
		);
		
		// insert into sidebar right after welcome panel
		$this->sidebarInsertPanel($sidebar, array('after' => 'welcome'), array('blogs' => $blogs));
		
		return $sidebar;
	}
}
?>